package br.com.inventario.jdbc.dao;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.inventario.jdbc.modelos.Inventario;

public class InventarioDAO {
	
	private final Session session;

	public InventarioDAO() {
	    this.session = CriadorDeSession.getSession();
	  }

public void adiciona(Inventario oinventario) {
	
    Transaction tx = session.beginTransaction();
	session.save(oinventario);
	tx.commit();
	session.close();
	}

public List<Inventario> lista() {
	
	Transaction tx = session.beginTransaction();
	List <Inventario> Inventarios = session.createQuery("from Inventario").list();
	tx.commit();
	return Inventarios;
	}

public Inventario buscaInventario(int id) {
	return (Inventario) this.session.load(Inventario.class, id);
	}

public void altera(Inventario oinventario) {
		
	Transaction tx = session.beginTransaction();
	session.update(oinventario);
	tx.commit();
	session.close();
	}

public void remove(Inventario oinventario) {
	
	Transaction tx = session.beginTransaction();
	session.delete(oinventario);
	tx.commit();
	session.close();

	}
}